package de.islanders.persistence;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import de.islanders.unit.player.Player;

public class SymptomDAO {

	private EntityManager entityManager;
	
	public void setEntityManager(EntityManager entityManager) {
        this.entityManager = entityManager;
    }

    protected EntityManager getEntityManager() {
        if (entityManager == null)
            throw new IllegalStateException(
                    "EntityManager has not been set on DAO before usage");
        return entityManager;
    }
    
    public Symptom findById(Integer id){
    	return entityManager.find(Symptom.class, id);
    }
    
    public List<Symptom> findSymptoms(Disease disease){
    	Query query = entityManager.createQuery("SELECT s FROM Symptom s WHERE disease = :disease");
    	query.setParameter("disease", disease);
    	return query.getResultList();
    }
    
    public void makePersistent(Symptom symptom){
    	entityManager.getTransaction().begin();
    	entityManager.persist(symptom);
    	entityManager.getTransaction().commit();
    }
}
